#!/bin/bash
SQOOP_HOME=/usr/bin/sqoop
if [[ $1 == "" ]];then
   TD_DATE=`date -d '1 days ago' "+%Y-%m-%d"`
else
   TD_DATE=$1
fi

# define var
SQOOP_HOME=/usr/bin/sqoop
JDBCSTR="jdbc:mysql://106.75.33.59:3306/nev"
MYSQL_USERNAME=itcast_edu_stu
MYSQL_PASSWORD=itcast_edu_stu
YEARSTR=`date -d "-1 day" +%Y`
MONTHSTR=`date -d "-1 day" +%m`
HIVE_DB=oe_ods
MAP_NUMBER=3

echo "执行采集web_chat_ems_${YEARSTR}_${MONTHSTR}的任务......"

$SQOOP_HOME import "-Dorg.apache.sqoop.splitter.allow_text_splitter=true" \
--connect $JDBCSTR \
--username $MYSQL_USERNAME \
--password $MYSQL_PASSWORD \
--query "select if(id is not null,1,0) as type_id ,*,CURRENT_DATE() AS dt from web_chat_ems_2019_07 where 1=1 and \$CONDITIONS" \
--fields-terminated-by '\t' \
--hcatalog-database $HIVE_DB \
--hcatalog-table web_chat_ems_2019_07 \
-m $MAP_NUMBER \
--split-by id

echo "执行采集web_chat_text_ems_${YEARSTR}_${MONTHSTR}的任务......"
$SQOOP_HOME import "-Dorg.apache.sqoop.splitter.allow_text_splitter=true" \
--connect $JDBCSTR \
--username $MYSQL_USERNAME \
--password $MYSQL_PASSWORD \
--query "select * from web_chat_text_ems_2019_07 where 1=1 and \$CONDITIONS" \
--fields-terminated-by '\t' \
--hcatalog-database $HIVE_DB \
--hcatalog-table web_chat_text_ems_2019_07 \
-m $MAP_NUMBER \
--split-by id
